<?php

namespace Home\Controller;
use Home\Controller\BaseController;
class MyMaterialController extends BaseController{
    public function index(){
        $user_id=session('id');
        $search=$_GET['search'];
        $status=$_GET['status'];
        $now_term=M('term_time')->field('last_year,first_year')->select();
//        var_dump($now_term);
//        处理学年下拉框
        //        列表数据处理
        if (isset($search) && !empty($search)) {
            $where['asset_name'] = ['like', '%' . $search . '%'];
        }
        if (isset($search) && $search === '0') {
            $where['asset_name'] = ['like', '%' . $search . '%'];
        }
        if (isset($status) && in_array($status, [1, 2])) {
            $where['status'] = intval($status);
        }

        $where['user_id']=$user_id;
//        分页
        $result = M('material_get')->where($where)->select();
        $count = count($result);
        $Page = new \Think\Page($count, 5);
        foreach ($where as $key => $val) {
            $Page->parameter[$key] = urlencode($val);
        }
        $Page->setConfig('next', '上一页');
        $Page->setConfig('prev', '下一页');
        $show = $Page->show();//

        $material_get = M('material_get')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->assign('count', $count);
        $this->assign('show', $show);
        $this->assign('material_get', $material_get);
//        var_dump($asset);
//        var_dump($count);

//        保存默认值
        if (isset($status) && in_array($status, [0, 1, 2])) {
            $this->assign('status', $status);
        }
        if (isset($search)) {
            $this->assign('name', $search);
        }

//        列表数据处理结束

        $this->assign('now_term',$now_term);
        $this->display('teacher/myMaterial');
    }
}